from collections import defaultdict, deque

def main():
    node_num, edge_num = map(int, input().split())
    visited = [False] * node_num
    
    node_dict = defaultdict(list)
    
    for i in range(edge_num):
        node1, node2 = map(int, input().split())
        node_dict[node1].append(node2)
    
    queue = deque()
    queue.append(1)
    
    while queue:
        node1 = queue.pop()
        visited[node1-1] = True
        
        for node2 in node_dict[node1]:
            if not visited[node2-1]:
                queue.append(node2)
    
    for i in range(node_num):
        if not visited[i]:
            print(-1)
            return -1
    print(1)
    return 1

main()